/**
 * @file Socket.h
 * @author your name (you@domain.com)
 * @brief
 * @version 0.1
 * @date 2022-04-05
 *
 * @copyright Copyright (c) 2022
 *
 */

#pragma once

#include "../utils/Noncopyable.h"

namespace wd
{
class InetAddress;
class Socket : Noncopyable
{
  public:
    Socket(int sockfd);
    Socket();
    ~Socket();

    void ready(const InetAddress &addr);

    int accept(); // peerfd
    void shutdownWrite();
    int fd() { return sockfd_; } // sockfd

    static InetAddress getLocalAddr(int sockfd);
    static InetAddress getPeerAddr(int sockfd);

  private:
    void bindAddress(const InetAddress &addr);
    void listen();
    void setReuseAddr(bool flag);
    void setReusePort(bool flag);

  private:
    int sockfd_;
};
} // end of namespace wd
